Fix compaction splitting tool-use/result pairs#326
Conversation
|
@wangle201210 is attempting to deploy a commit to the crazyboym's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@wangle201210 |
@Gui-Yue 现在简化了很多写法,用来做学习应该问题不大了 |
Preserve assistant tool_use / user tool_result adjacency when compaction trims message history. Fixes shareAI-lab#325. Squashed original PR commits: - Fix compaction breaking tool-use/result pairs - Simplify compaction boundary fix
Summary
Fixes #325.
This updates context compaction so it preserves complete tool rounds instead of trimming raw message slices.
The bug was that
snip_compactandreactive_compactcould separate an assistant message containingtool_useblocks from the following user message containingtool_resultblocks. That leaves orphaned tool results in history and can break the next model request.Changes
s08_context_compact,s09_memory, ands20_comprehensivesnip_compacttrim by complete tool rounds instead of raw message countreactive_compactretain a safe tail instead ofmessages[-5:]s08_context_compactdocs and generated site docs to describe the constraint correctlyValidation
python3 -m py_compile s08_context_compact/code.py s09_memory/code.py s20_comprehensive/code.py